"""
Author: Gaoqiang Du
Description：获取apifox的模板，不用OpenAPI的原因是其以path作为接口的key
Time: 2022/4/17 22:04
"""


def get_dir_template():
    """获取根目录下分组目录模板，将api模板导入至items内"""
    return {
        "name": "文件目录",
        "parentId": 0,
        "serverId": "",
        "description": "",
        "preProcessors": [],
        "postProcessors": [],
        "auth": {},
        "items": []
    }


def get_success_res_example(data=""):
    return {
        "name": "成功示例 ",
        "data": data,
        "responseId": 123345,
        "ordering": 1
    }


def get_json_res_template():
    return {
        "id": "",
        "name": "成功",
        "code": 200,
        "contentType": "json",
        "jsonSchema": {
            "type": "object",
            "properties": {},
            "required": []
        }
    }


def get_api_item_template():
    """获取单个接口文档的模板，只需要注意其中几个元素即可"""
    return {
        "name": "接口名称",
        "api": {
            "id": "",
            "method": "get",
            "path": "/",
            "parameters": {
                "query": []
            },
            "auth": {},
            "commonParameters": {
                "query": [],
                "body": [],
                "cookie": [],
                "header": []
            },
            "responses": [],  # 见 get_json_res_template 方法
            "responseExamples": [],
            "requestBody": {
                "type": "none",
                "parameters": []
            },
            "description": "该接口竟然没有描述！",
            "tags": [],
            "status": "released",
            "serverId": "",
            "operationId": "",
            "sourceUrl": "",
            "ordering": 0,
            "cases": [],
            "mocks": []
        }
    }


def get_default_apifox_template():
    return {
        "apifoxProject": "1.0.0",
        "info": {  # 项目相关
            "name": "project_name",  # 项目名
            "description": "",
            "mockRule": {
                "rules": [],
                "enableSystemRule": True
            }
        },
        "responseCollection": [],
        "apiCollection": [
            {
                "name": "根目录",
                "parentId": 0,
                "serverId": "",
                "description": "",
                "preProcessors": [],
                "postProcessors": [],
                "auth": {},
                "items": []
            }
        ],
        "socketCollection": [],
        "docCollection": [],
        "schemaCollection": [],
        "apiTestCaseCollection": [
            {
                "name": "默认分组",
                "children": [],
                "items": []
            }
        ],
        "apiTestSuiteCollection": [],
        "environments": [],  # 环境参数
        "commonScripts": [],  # 公共脚本
        "databaseConnections": [],
        "globalVariables": [],
        "commonParameters": None,
        "projectSetting": {
            "apiStatuses": [
                "developing",
                "testing",
                "released",
                "deprecated"
            ],
            "servers": [
                {
                    "id": "default",
                    "name": "默认服务"
                }
            ],
            "preProcessors": [],  # 前置操作
            "postProcessors": [],
            "auth": {
                "type": "apikey",
                "apikey": {
                    "in": "header",
                    "key": "X-Auth-Token"
                }
            },
            "id": ""
        }
    }
